package 中等;

public class 二叉搜索树中第K小的元素 {


    int rank = 0;

    int res = 0;

    public int kthSmallest(TreeNode root, int k) {
        traverse(root,k );
        return res;
    }
    public void traverse(TreeNode root, int k){
        if(root == null){
            return;
        }
        traverse(root.left,k );
        rank++;
        if (rank == k){
            res  = root.val;
            return;
        }
        traverse(root.right,k );
    }
}
